//
//  SqDetailListViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/8/3.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "HomeDetailFinshtViewController.h"
#import "SqFinshViewCell.h"
@interface HomeDetailFinshtViewController ()
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
- (IBAction)leftBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *centerBtn;
- (IBAction)centerBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
- (IBAction)rightBtn:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIView *footView;

@property (weak, nonatomic) IBOutlet UILabel *codeLabel;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *shenqLabel;
@property (weak, nonatomic) IBOutlet UILabel *bumenLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *spTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *spBumenLabel;
@property (weak, nonatomic) IBOutlet UILabel *spContnetLabel;

@property (weak, nonatomic) IBOutlet UIView *contentView;

@property (nonatomic ,strong) AppealFinshModel *model;
@property (nonatomic, strong) YMTextView *textView;
@property (nonatomic, copy) NSString *auth;
@property (nonatomic ,copy) NSString *type;

@end

@implementation HomeDetailFinshtViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"诉求详情";
    self.tableView.rowHeight = 120;
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"SqFinshViewCell" bundle:nil] forCellReuseIdentifier:@"SqFinshViewCell"];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.textView=[[YMTextView alloc]init];
        [self.contentView addSubview:self.textView];
        self.textView.maxNumb = 200;
        //self.textView.placeholderColor = [UIColor grayColor];
        self.textView.textFont = [UIFont systemFontOfSize:15];

        [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.mas_equalTo(0);
        }];
        self.textView.placeholder = @"办理意见";
        self.textView.isFinishKeyboard = YES;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.leftBtn.selected = YES;
    
    self.centerBtn.selected = NO;
    self.rightBtn.selected = NO;
    self.type =@"1";
    
    [self getData];
}

#pragma mark - Table view data source




//时间戳变为格式时间
- (NSString *)ConvertStrToTime:(NSString *)timeStr{
    long long time=[timeStr longLongValue];
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString*timeString=[formatter stringFromDate:date];
    return timeString;
    
}

-(void)getData{
    
    if ([[TokenManager getLeader_main] isEqualToString:@"1"]) {
        if ([[TokenManager getIsheadOffice] isEqualToString:@"1"]) {
            self.auth = @"5";
        }else{
            self.auth = @"2";
        }
    }else if ([[TokenManager getSection_normal]isEqualToString:@"1"]){
        
        if ([[TokenManager getIsheadOffice]isEqualToString:@"1"]) {
            self.auth = @"6";
        }else{
            self.auth = @"3";
        }
    }
    WS(weakSelf);
    [[ApiManager ShardInstance]staffAppealDetailID:self.appealID  resultBlock:^(NSDictionary *data, NSError *error) {
        
        
        self.model = [AppealFinshModel mj_objectWithKeyValues:data[@"rs"]];
        
        
        weakSelf.nameLabel.text = [NSString stringWithFormat:@"%@提交的%@",self.model.appeal.real_name,self.model.appeal.type_name];
        weakSelf.codeLabel.text = self.model.appeal.appeal_code;
        weakSelf.shenqLabel.text = self.model.appeal.real_name;
        weakSelf.bumenLabel.text = self.model.appeal.section_name;
        weakSelf.timeLabel.text = [self ConvertStrToTime:self.model.appeal.create_time];
        weakSelf.typeLabel.text = self.model.appeal.type_name;
        weakSelf.contentLabel.text = self.model.appeal.content;
        
        weakSelf.spTimeLabel.text = [self ConvertStrToTime:self.model.result.create_time];
        weakSelf.spBumenLabel.text = self.model.result.section_name;
        weakSelf.spContnetLabel.text = self.model.result.content;
        
        
        
        [self.tableView reloadData];
        
        
    }];
    
}
- (IBAction)leftBtn:(UIButton *)sender {
    sender.selected = YES;
    self.centerBtn.selected = NO;
    self.rightBtn.selected = NO;
    self.type = @"1";
    
}
- (IBAction)centerBtn:(UIButton *)sender {
    sender.selected = YES;
    self.leftBtn.selected = NO;
    self.rightBtn.selected = NO;
    self.type = @"2";
}
- (IBAction)rightBtn:(UIButton *)sender {
    sender.selected = YES;
    self.centerBtn.selected = NO;
    self.leftBtn.selected = NO;
    self.type = @"3";
}
- (IBAction)commitBtn:(UIButton *)sender {
    [[ApiManager ShardInstance]appraiseParent_id:self.model.appeal.id staff_id:[TokenManager getUserId] type:self.type content:self.textView.textView.text resultBlock:^(NSDictionary *data, NSError *error) {
       
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [[ToastManager shardInstance]showToast:model.msg];
        }
        
    }];
    
}

@end
